﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yule.Service.Sys
{
    /// <summary>
    /// 地区服务类
    /// </summary>
    public class Region : BaseService, yule.IService.Sys.IRegion
    {

        #region IRegion 成员

        public Model.Sys.Region GetRegion(string id)
        {
            return new DAL.Sys.Region().Select(id);
        }

        public IList<Model.Sys.Region> GetRegionList()
        {
            return new DAL.Sys.Region().List();
        }

        public bool Update(Model.Sys.Region model)
        {

            

            int val = 0;

            if (model != null)
            {
                model.PathId = yule.Model.TreeHelper.GetPathId<yule.Model.Sys.Region>(model);
                model.PathName = yule.Model.TreeHelper.GetPathName<yule.Model.Sys.Region>(model);

                yule.Data.Transaction tran = yule.Data.DBHelper.Instance.CreateTransaction();

                try
                {
                    val = new DAL.Sys.Region().UpdateX(model, tran);
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    throw;
                }
                finally
                {
                    tran.Dispose();
                }
            }

            return val > 0;
        }

        #endregion
    }

}